/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.Server;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*    */ import com.zimbra.cs.db.DbMailbox;
/*    */ import com.zimbra.cs.db.DbPool;
/*    */ import com.zimbra.cs.db.DbPool.DbConnection;
/*    */ import com.zimbra.cs.mailbox.Mailbox.MailboxData;
/*    */ import com.zimbra.cs.session.AdminSession;
/*    */ import com.zimbra.cs.session.Session.Type;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class GetMailboxStats
/*    */   extends AdminDocumentHandler
/*    */ {
/*    */   private static final String GET_MAILBOX_STATS_CACHE_KEY = "GetMailboxStats";
/*    */   
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 41 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*    */     
/* 43 */     Server localServer = Provisioning.getInstance().getLocalServer();
/* 44 */     checkRight(zsc, context, localServer, Rights.Admin.R_getMailboxStats);
/*    */     
/* 46 */     MailboxStats stats = null;
/*    */     
/* 48 */     AdminSession session = (AdminSession)getSession(zsc, Session.Type.ADMIN);
/* 49 */     if (session != null) {
/* 50 */       MailboxStats cachedStats = (MailboxStats)session.getData("GetMailboxStats");
/* 51 */       if (cachedStats == null) {
/* 52 */         stats = doStats();
/* 53 */         session.setData("GetMailboxStats", stats);
/*    */       } else {
/* 55 */         stats = cachedStats;
/*    */       }
/*    */     } else {
/* 58 */       stats = doStats();
/*    */     }
/*    */     
/* 61 */     Element response = zsc.createElement(AdminConstants.GET_MAILBOX_STATS_RESPONSE);
/* 62 */     Element statsElem = response.addElement("stats");
/* 63 */     statsElem.addAttribute("numMboxes", stats.mNumMboxes);
/* 64 */     statsElem.addAttribute("totalSize", stats.mTotalSize);
/* 65 */     return response;
/*    */   }
/*    */   
/*    */   private static class MailboxStats {
/* 69 */     long mNumMboxes = 0L;
/* 70 */     long mTotalSize = 0L;
/*    */   }
/*    */   
/*    */   private MailboxStats doStats() throws ServiceException {
/* 74 */     List<Mailbox.MailboxData> mailboxes = doSearch();
/* 75 */     MailboxStats stats = new MailboxStats(null);
/*    */     
/* 77 */     for (Mailbox.MailboxData m : mailboxes) {
/* 78 */       stats.mNumMboxes += 1L;
/* 79 */       stats.mTotalSize += m.size;
/*    */     }
/*    */     
/* 82 */     return stats;
/*    */   }
/*    */   
/*    */   private List<Mailbox.MailboxData> doSearch() throws ServiceException {
/* 86 */     List<Mailbox.MailboxData> result = null;
/* 87 */     DbPool.DbConnection conn = null;
/*    */     try {
/* 89 */       conn = DbPool.getConnection();
/* 90 */       result = DbMailbox.getMailboxRawData(conn);
/*    */     } finally {
/* 92 */       DbPool.quietClose(conn);
/*    */     }
/* 94 */     return result;
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 99 */     relatedRights.add(Rights.Admin.R_getMailboxStats);
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetMailboxStats.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */